/*
 * Class
 * DefaultLanguageJDialog
 */
package pl.abstractvoid.gui.configuration;

import pl.abstractvoid.settings.SettingsProvider;
import java.awt.Image;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.SwingConstants;
import pl.abstractvoid.gui.UtilsGUI;

/**
 * Represents the dialog window which lets the user choose the default language.
 * <p>
 * Flags downloaded from: http://www.free-country-flags.com/countries.php
 *
 * @author Ivo Zieliński
 */
public class DefaultLanguageJDialog extends javax.swing.JDialog {

    /**
     * Image of the English flag.
     */
    private Image englishFlag;
    /**
     * Image of the Polish flag.
     */
    private Image polishFlag;

    /**
     * Creates new form DefaultLanguageJDialog
     *
     * @param parent
     * @param modal
     */
    public DefaultLanguageJDialog(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        try {
            englishFlag = UtilsGUI.createImage("/United_Kingdom.png");
            polishFlag = UtilsGUI.createImage("/Poland.png");
        } catch (IOException ex) {
            Logger.getLogger(DefaultLanguageJDialog.class.getName()).log(Level.SEVERE, null, ex);
        }
        initComponents();
        setTitle("Choose your language");
        englishJButton.setIcon(new ImageIcon(englishFlag));
        polishJButton.setIcon(new ImageIcon(polishFlag));
        englishJButton.setVerticalTextPosition(SwingConstants.BOTTOM);
        englishJButton.setHorizontalTextPosition(SwingConstants.CENTER);
        polishJButton.setVerticalTextPosition(SwingConstants.BOTTOM);
        polishJButton.setHorizontalTextPosition(SwingConstants.CENTER);
        setResizable(false);
        setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
        pack();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        englishJButton = new javax.swing.JButton();
        polishJButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        englishJButton.setText("ENGLISH");
        englishJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                englishJButtonActionPerformed(evt);
            }
        });

        polishJButton.setText("POLSKI");
        polishJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                polishJButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(englishJButton, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(polishJButton, javax.swing.GroupLayout.DEFAULT_SIZE, 144, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(englishJButton, javax.swing.GroupLayout.DEFAULT_SIZE, 99, Short.MAX_VALUE)
            .addComponent(polishJButton, javax.swing.GroupLayout.DEFAULT_SIZE, 99, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void englishJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_englishJButtonActionPerformed
        try {
            SettingsProvider.getInstance().setProperty("defaultLanguage", "en");
        } catch (IOException ex) {
            Logger.getLogger(DefaultLanguageJDialog.class.getName()).log(Level.SEVERE, null, ex);
        }
        dispose();
    }//GEN-LAST:event_englishJButtonActionPerformed

    private void polishJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_polishJButtonActionPerformed
        try {
            SettingsProvider.getInstance().setProperty("defaultLanguage", "pl");
        } catch (IOException ex) {
            Logger.getLogger(DefaultLanguageJDialog.class.getName()).log(Level.SEVERE, null, ex);
        }
        dispose();
    }//GEN-LAST:event_polishJButtonActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton englishJButton;
    private javax.swing.JButton polishJButton;
    // End of variables declaration//GEN-END:variables
}
